package com.fernandomartines.dbcheck.app.view;

import com.fernandomartines.dbcheck.test.entities.TestSuite;
import com.fernandomartines.dbcheck.util.StringUtil;
import java.awt.event.ActionListener;

public class TestSuiteItemTemplateView extends javax.swing.JPanel {

    private ActionListener actionListener;

    public TestSuiteItemTemplateView(TestSuite testSuite, ActionListener actionListener) {
        this.actionListener = actionListener;

        initComponents();
        String tcs = testSuite.getTestCases().size() != 1 ?
            testSuite.getTestCases().size() + " test cases" : "1 test case";
        labelTestSuite.setText("<html>#" + testSuite.getId() + "<br><b>" + testSuite.getName() + "<b><br><font color=#a0a0a0 size=3>" + tcs + "</font></html>");
        labelPassRate.setText("<html>Pass Rate<br>" + StringUtil.formatNumber(testSuite.getPassRate(), "#0.0") + "%");
        buttonOpen.setActionCommand("OPEN_TEST_SUITE_" + testSuite.getId());
        buttonOpen.addActionListener(actionListener);
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelIcon = new javax.swing.JLabel();
        labelTestSuite = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        labelPassRate = new javax.swing.JLabel();
        buttonOpen = new javax.swing.JButton();

        setBackground(new java.awt.Color(175, 175, 175));
        setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.white, java.awt.Color.gray, java.awt.Color.lightGray));
        setPreferredSize(new java.awt.Dimension(290, 65));
        setLayout(new java.awt.BorderLayout());

        labelIcon.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/fernandomartines/dbcheck/app/view/resources/dbCheck-db-icon.png"))); // NOI18N
        labelIcon.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        labelIcon.setPreferredSize(new java.awt.Dimension(60, 0));
        add(labelIcon, java.awt.BorderLayout.WEST);

        labelTestSuite.setFont(new java.awt.Font("Tahoma", 1, 14));
        labelTestSuite.setText("<html>000<br>test suite name");
        add(labelTestSuite, java.awt.BorderLayout.CENTER);

        jPanel1.setOpaque(false);
        jPanel1.setPreferredSize(new java.awt.Dimension(65, 10));

        labelPassRate.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        labelPassRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelPassRate.setText("0%");

        buttonOpen.setText("Open");
        buttonOpen.setPreferredSize(new java.awt.Dimension(45, 23));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(buttonOpen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 45, Short.MAX_VALUE)
                    .addComponent(labelPassRate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(labelPassRate, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonOpen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );

        add(jPanel1, java.awt.BorderLayout.EAST);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonOpen;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelIcon;
    private javax.swing.JLabel labelPassRate;
    private javax.swing.JLabel labelTestSuite;
    // End of variables declaration//GEN-END:variables

}
